<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>裁剪数字后查询第 K 小的数字</title>
</head>
<body>
  <script>
    function fn(nums, queries) {
      let result = [];
      for (let i = 0; i < queries.length; i++) {
        help(queries[i][0], queries[i][1], result)
      }
      function help(k, trim, result) {
        let temp = [];
        for (let i = 0; i < nums.length; i++) {
          temp.push([nums[i].substr(-trim), i]);
        }
        let cloneTemp = [...temp].sort(compareNum);
        result.push(temp.indexOf(cloneTemp[k - 1]))
      }
      function compareNum(a, b) {
        if (a[0] < b[0]) {
          return -1;
        } else if (a[0] === b[0]) {
          return 0
        }
        return 1;
      }
      return result
    }
    console.log(fn(['102', '473', '251', '814'], [[1, 1], [2, 3], [4, 2], [1, 2]]))
  </script>
</body>
</html>